package View;

import java.io.Serializable;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import Controller.ReportsController;
import Entity.CommentReport;
import java.awt.List;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/** this class provide the GUI window in order to produce comment report */
public class CommentReportResultView extends JFrame implements Serializable {

	private static final long serialVersionUID = 42L;

	/**required fields, buttons and attribute */
	private JTextField SaleID;
	private JTextField TotalCustomers;
	private JTextField TotalTime;
	private JTextField TotalSales;
	private JLabel lblCommentsFrom;
	private JLabel lblCustomersThat;
	private JLabel lblDidntBought;
	private JLabel lblTheSaleProduct;
	List list;
	ReportsController reportsController=( ReportsController	) this.reportsController;

	/** default and only constructor */
	public CommentReportResultView( CommentReport Cmt, String SID) 
	{
		setAlwaysOnTop(true);
		getContentPane().setFont(new Font("Tahoma", Font.BOLD, 12));	
		setTitle("Comment Report");

		this.setSize(472, 542);
		setResizable(false);
		getContentPane().setLayout(null);

		JLabel lblSaleid = new JLabel("SaleID Number");
		lblSaleid.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblSaleid.setBounds(10, 34, 175, 17);
		getContentPane().add(lblSaleid);

		JLabel lblNewLabel = new JLabel("Total Customers In This Sale");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblNewLabel.setBounds(10, 71, 175, 29);
		getContentPane().add(lblNewLabel);

		JLabel lblTotalTime = new JLabel("Total PhoneCalls Time In Minutes");
		lblTotalTime.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblTotalTime.setBounds(10, 111, 205, 14);
		getContentPane().add(lblTotalTime);

		JLabel lblTotalSales = new JLabel("Total Sales Done");
		lblTotalSales.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblTotalSales.setBounds(10, 151, 164, 14);
		getContentPane().add(lblTotalSales);

		SaleID = new JTextField(SID);
		SaleID.setEditable(false);
		SaleID.setFont(new Font("Tahoma", Font.BOLD, 15));
		SaleID.setBounds(253, 32, 164, 20);
		getContentPane().add(SaleID);
		SaleID.setColumns(10);

		TotalCustomers = new JTextField(Integer.toString(Cmt.getTotalCustomers())+" Customers Bought ");
		TotalCustomers.setFont(new Font("Tahoma", Font.BOLD, 15));
		TotalCustomers.setBounds(253, 73, 164, 20);
		getContentPane().add(TotalCustomers);
		TotalCustomers.setColumns(10);

		TotalTime = new JTextField(Integer.toString(Cmt.getTotalTime())+" Minutes");
		TotalTime.setFont(new Font("Tahoma", Font.BOLD, 15));
		TotalTime.setBounds(253, 106, 165, 20);
		getContentPane().add(TotalTime);
		TotalTime.setColumns(10);

		TotalSales = new JTextField(Integer.toString(Cmt.getTotalSales())+" Sales");
		TotalSales.setFont(new Font("Tahoma", Font.BOLD, 15));
		TotalSales.setBounds(253, 151, 165, 20);
		getContentPane().add(TotalSales);
		TotalSales.setColumns(10);

		lblCommentsFrom = new JLabel("Comments From");
		lblCommentsFrom.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblCommentsFrom.setBounds(10, 282, 114, 14);
		getContentPane().add(lblCommentsFrom);

		lblCustomersThat = new JLabel("Customers That");
		lblCustomersThat.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblCustomersThat.setBounds(10, 307, 107, 14);
		getContentPane().add(lblCustomersThat);

		lblDidntBought = new JLabel("Didn't Bought");
		lblDidntBought.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblDidntBought.setBounds(10, 332, 107, 14);
		getContentPane().add(lblDidntBought);

		lblTheSaleProduct = new JLabel("The Sale Product");
		lblTheSaleProduct.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblTheSaleProduct.setBounds(10, 357, 114, 14);
		getContentPane().add(lblTheSaleProduct);

		JButton btnBack = new JButton("Back");
		btnBack.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e) 
			{
				hideWindow();
				reportsController.showWindow();	
			}
		});

		btnBack.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnBack.setBounds(22, 449, 89, 29);
		getContentPane().add(btnBack);

		list = new List();
		list.setBounds(130, 187, 313, 305);
		getContentPane().add(list);
		for(int i=0;i<Cmt.getCommentsArraySize();i++)
		{   

			list.add(String.valueOf(i+1)+ " : "  +
					"              " +    Cmt.getTotalComments()[i]);
			list.add("");
		}
		this.setLocationRelativeTo(null); 
		this.showWindow();
	}

	/**show and hide window functions */
	public void showWindow()
	{
		setVisible(true);	
	}
	public void hideWindow()
	{
		setVisible(false);
	}

	/**get list function*/
	public List getList() 
	{
		return list;
	}
}